package org.example.scenicspot.persistence;

import org.apache.ibatis.annotations.*;
import org.example.scenicspot.domain.ScenicSpot;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface scenicSpotMapper {
    @Select("select * from scenicSpotmsg")
    List<ScenicSpot> selectAll();

    @Select("SELECT * FROM scenicSpotmsg WHERE scenicSpotmsg.name LIKE CONCAT('%', #{name}, '%')")
    List<ScenicSpot> selectByName(@Param("name") String name);

    @Select("SELECT * FROM scenicSpotmsg WHERE scenicSpotmsg.id = #{id}")
    ScenicSpot selectByID(int id);

    @Delete("DELETE FROM scenicSpotmsg WHERE scenicSpotmsg.id = #{id}")
    int deleteById(@Param("id") Integer id);

    @Insert("INSERT INTO scenicSpotmsg (id,name,MaxCapacity,ParkingLotCapacity,GeographicLocation,ElectronicMapURL,score) VALUES (#{id},#{name}, #{MaxCapacity}, #{ParkingLotCapacity}, #{GeographicLocation}, #{ElectronicMapURL},#{score})")
    void insert(int id,String name,int MaxCapacity,int ParkingLotCapacity,String GeographicLocation,String ElectronicMapURL,String score);

    @Update("UPDATE scenicSpotmsg SET name = #{name}, MaxCapacity = #{MaxCapacity}, ParkingLotCapacity = #{ParkingLotCapacity}, " +
            "GeographicLocation = #{GeographicLocation}, ElectronicMapURL = #{ElectronicMapURL},Score = #{Score} WHERE id = #{id}")
    void update(@Param("id") int id,@Param("name") String name,@Param("MaxCapacity") int MaxCapacity,@Param("ParkingLotCapacity") int ParkingLotCapacity,@Param("GeographicLocation") String GeographicLocation,@Param("ElectronicMapURL") String ElectronicMapURL,@Param("Score") String Score);
    @Update("update scenicSpotmsg set score=#{score} where id=#{id}")
    void updateScore(@Param("id") int id,@Param("score") String score);
}
